package cli.command;

import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;

public class MakeDirectory implements Command {
    private PrintWriter out;
    private Path currentPath;

    public MakeDirectory(PrintWriter out, Path currentPath) {
        this.out = out;
        this.currentPath = currentPath;
    }

    @Override
    public void handle(String[] args) {
        if (args.length == 0) {
            out.println("请输入路径！");
            return;
        }
        Path path = currentPath.resolve(args[0]);
        try {
            Files.createDirectory(path);
        } catch (FileAlreadyExistsException e) {
            out.println("存在同名文件或文件夹！");
        } catch (IOException e) {
            out.println("路径无效！");
        }
    }
}
